package com.eschool.service.impl;

import java.util.Iterator;
import java.util.List;

import com.eschool.dao.ClassDao;
import com.eschool.dao.CourseDao;
import com.eschool.dao.RoomDao;
import com.eschool.dao.SectionDao;
import com.eschool.dao.SessionDao;
import com.eschool.model.Clas;
import com.eschool.model.Course;
import com.eschool.model.Room;
import com.eschool.model.Section;
import com.eschool.service.SchoolManagementService;
import com.eschool.util.ConstraintsUtil;
import com.eschool.util.UserUtil;

public class SchoolManagementServiceImpl implements SchoolManagementService{

	public boolean addRoom(Room room){
		room.setBranch(UserUtil.currentUser().getBranch());
		
		return RoomDao.addRoom(room);
	}

	@Override
	 public boolean addSection(Section section) {
	  return SectionDao.addSection(section);
	 }
	
	
	@Override
	public boolean addCourse(Course course) {
		course.setBranch(UserUtil.currentUser().getBranch());
		return CourseDao.addCourse(course);
	}

	@Override
	public boolean addSession(com.eschool.model.Session session) {
		session.setBranch(UserUtil.currentUser().getBranch());
		
		session.setUser(UserUtil.currentUser());
		
		return SessionDao.addSession(session);
	}

	@Override
	public boolean addClass(Clas clas) {
		
		clas.setBranch(UserUtil.currentUser().getBranch());
		
		return ClassDao.addClass(clas);
	}

	@Override
	public boolean updateRoomsStatus(List<Room> rooms, boolean newStatus) {
		for (Iterator iterator = rooms.iterator(); iterator.hasNext();){
			Room room = (Room) iterator.next();
			room.setStatus(newStatus);
			RoomDao.updateRoom(room);
		}
		
		
		return true;
	}

	@Override
	public boolean updateCoursesStatus(List<Course> courses, boolean newStatus) {
		for (Iterator iterator = courses.iterator(); iterator.hasNext();){
			Course course = (Course) iterator.next();
			course.setCurrentStatus(newStatus);
			CourseDao.updateCourse(course);
		}
		
		
		return true;
	}

	@Override
	public boolean updateClassesStatus(List<Clas> classes, boolean newStatus) {
		for (Iterator iterator = classes.iterator(); iterator.hasNext();){
			Clas clas= (Clas) iterator.next();
			clas.setCurrentStatus(newStatus);
			ClassDao.updateClass(clas);
		}
		return true;
	}

	@Override
	public List<Course> getAllCourses() {
		// TODO Auto-generated method stub
		return CourseDao.getCourses(ConstraintsUtil.getConstraintsMap());
	}
}
